home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / flkatck.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  168 lines

  1. /***************************************************************************
  2.  
  3.   Functions to emulate the video hardware of the machine.
  4.  
  5. ***************************************************************************/
  6.  
  7. #include "driver.h"
  8. #include "vidhrdw/konamiic.h"
  9. #include "vidhrdw/generic.h"
  10.  
  11. static struct tilemap *k007121_tilemap[2];
  12.  
  13. unsigned char *k007121_ram;
  14.  
  15. int flkatck_irq_enabled;
  16.  
  17. static int k007121_flip_screen = 0;
  18.  
  19. /***************************************************************************
  20.  
  21.   Callbacks for the K007121
  22.  
  23. ***************************************************************************/
  24.  
  25. static void get_tile_info_A(int tile_index)
  26. {
  27.     int attr = k007121_ram[tile_index];
  28.     int code = k007121_ram[tile_index+0x400];
  29.     int bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
  30.     int bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
  31.     int bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
  32.     int bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
  33.     int bank = ((attr & 0x80) >> 7) |
  34.             ((attr >> (bit0+2)) & 0x02) |
  35.             ((attr >> (bit1+1)) & 0x04) |
  36.             ((attr >> (bit2  )) & 0x08) |
  37.             ((attr >> (bit3-1)) & 0x10) |
  38.             ((K007121_ctrlram[0][0x03] & 0x01) << 5);
  39.     int mask = (K007121_ctrlram[0][0x04] & 0xf0) >> 4;
  40.  
  41.     bank = (bank & ~(mask << 1)) | ((K007121_ctrlram[0][0x04] & mask) << 1);
  42.  
  43.     if ((attr == 0x0d) && (!(K007121_ctrlram[0][0])) && (!(K007121_ctrlram[0][2])))
  44.         bank = 0;    /*    this allows the game to print text
  45.                     in all banks selected by the k007121 */
  46.     tile_info.flags = (attr & 0x20) ? TILE_FLIPY : 0;
  47.  
  48.     SET_TILE_INFO(0, code + 256*bank, (attr & 0x0f) + 16)
  49. }
  50.  
  51. static void get_tile_info_B(int tile_index)
  52. {
  53.     int attr = k007121_ram[tile_index+0x800];
  54.     int code = k007121_ram[tile_index+0xc00];
  55.  
  56.     SET_TILE_INFO(0, code, (attr & 0x0f) + 16)
  57. }
  58.  
  59.  
  60. /***************************************************************************
  61.  
  62.   Start the video hardware emulation.
  63.  
  64. ***************************************************************************/
  65.  
  66. int flkatck_vh_start(void)
  67. {
  68.     k007121_tilemap[0] = tilemap_create(get_tile_info_A,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,32);
  69.     k007121_tilemap[1] = tilemap_create(get_tile_info_B,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,32);
  70.  
  71.     if (!k007121_tilemap[0] || !k007121_tilemap[1])
  72.         return 1;
  73.  
  74.     {
  75.         struct rectangle clip = Machine->drv->visible_area;
  76.         clip.min_x += 40;
  77.         tilemap_set_clip(k007121_tilemap[0],&clip);
  78.  
  79.         clip.max_x = 39;
  80.         clip.min_x = 0;
  81.         tilemap_set_clip(k007121_tilemap[1],&clip);
  82.  
  83.         return 0;
  84.     }
  85. }
  86.  
  87.  
  88. /***************************************************************************
  89.  
  90.   Memory handlers
  91.  
  92. ***************************************************************************/
  93.  
  94. WRITE_HANDLER( flkatck_k007121_w )
  95. {
  96.     if (offset < 0x1000){    /* tiles */
  97.         if (k007121_ram[offset] != data)
  98.         {
  99.             k007121_ram[offset] = data;
  100.             if (offset & 0x800)    /* score */
  101.                 tilemap_mark_tile_dirty(k007121_tilemap[1],offset & 0x3ff);
  102.             else
  103.                 tilemap_mark_tile_dirty(k007121_tilemap[0],offset & 0x3ff);
  104.         }
  105.     }
  106.     else    /* sprites */
  107.         k007121_ram[offset] = data;
  108. }
  109.  
  110. WRITE_HANDLER( flkatck_k007121_regs_w )
  111. {
  112.     switch (offset)
  113.     {
  114.         case 0x04:    /* ROM bank select */
  115.             if (data != K007121_ctrlram[0][0x04])
  116.                 tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
  117.             break;
  118.  
  119.         case 0x07:    /* flip screen + IRQ control */
  120.             k007121_flip_screen = data & 0x08;
  121.             tilemap_set_flip(ALL_TILEMAPS, k007121_flip_screen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  122.             flkatck_irq_enabled = data & 0x02;
  123.             break;
  124.     }
  125.  
  126.     K007121_ctrl_0_w(offset,data);
  127. }
  128.  
  129.  
  130. /***************************************************************************
  131.  
  132.     Display Refresh
  133.  
  134. ***************************************************************************/
  135.  
  136. /***************************************************************************
  137.  
  138.     Flack Attack sprites. Each sprite has 16 bytes!:
  139.  
  140.  
  141. ***************************************************************************/
  142.  
  143. void flkatck_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  144. {
  145. #if 0
  146. usrintf_showmessage("%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x  %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
  147.     K007121_ctrlram[0][0x00],K007121_ctrlram[0][0x01],K007121_ctrlram[0][0x02],K007121_ctrlram[0][0x03],K007121_ctrlram[0][0x04],K007121_ctrlram[0][0x05],K007121_ctrlram[0][0x06],K007121_ctrlram[0][0x07],
  148.     K007121_ctrlram[1][0x00],K007121_ctrlram[1][0x01],K007121_ctrlram[1][0x02],K007121_ctrlram[1][0x03],K007121_ctrlram[1][0x04],K007121_ctrlram[1][0x05],K007121_ctrlram[1][0x06],K007121_ctrlram[1][0x07]);
  149. #endif
  150.     tilemap_update( ALL_TILEMAPS );
  151.  
  152.     palette_init_used_colors();
  153.     K007121_mark_sprites_colors(0,&k007121_ram[0x1000],0,0);
  154.     if (palette_recalc())
  155.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  156.  
  157.     tilemap_render(ALL_TILEMAPS);
  158.  
  159.     /* set scroll registers */
  160.     tilemap_set_scrollx(k007121_tilemap[0],0,K007121_ctrlram[0][0x00] - 40);
  161.     tilemap_set_scrolly(k007121_tilemap[0],0,K007121_ctrlram[0][0x02]);
  162.  
  163.     /* draw the graphics */
  164.     tilemap_draw(bitmap,k007121_tilemap[0],0);
  165.     K007121_sprites_draw(0,bitmap,&k007121_ram[0x1000],0,40,0,-1);
  166.     tilemap_draw(bitmap,k007121_tilemap[1],0);
  167. }
  168.